﻿<?php
/* Subversion Keywords:
 *
 * $Id$
 * $Date$
 * $Revision$
 * $Author$
 * $URL$
 *
 * Copyright (C) 2006 Livid Liu <v2ex.livid@mac.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

error_reporting(E_ALL|E_STRICT);
$conf = array('time_zone' => 'Asia/Shanghai');
date_default_timezone_set($conf['time_zone']); //（设置时区,在手册附录H中找对应的时区）
//目录分隔符号
$ds = DIRECTORY_SEPARATOR;
//路径分隔符号
$ps = PATH_SEPARATOR;
$ABS_ROOT_PATH = realpath(dirname(__FILE__));
$REL_ROOT_PATH =  substr($_SERVER['PHP_SELF'], 0 , strpos($_SERVER['PHP_SELF'],'/index.php'));
	set_include_path('.' . PATH_SEPARATOR . './library'
	. PATH_SEPARATOR . './application/modules/'
	. PATH_SEPARATOR . './library/Custom'
	. PATH_SEPARATOR . get_include_path());
	include "Zend/Loader.php";
//自动加载类
function __autoload($class){
    Zend_Loader::loadClass($class);
}
// 加载配置
$config = new Zend_Config_Ini('./config/config.ini', 'general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);
Zend_Registry::set('config',$config);
// 设置数据库
$db = Zend_Db::factory($config->db->adapter, $config->db->config->toArray());
$db->query("set names {$config->charset};");
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('db',$db);

//SMARTY配置
$smartyParams = new Zend_Config_Ini('./config/smarty.ini', 'Smarty');
$smarty = new Custom_View_Smarty($smartyParams->toArray());
$smarty->template_dir  = $smartyParams->template_dir;

Zend_Registry::set('smarty',$smarty);

// Create auth object
$auth = Zend_Auth::getInstance();

// Create acl object
$acl = new Custom_Acl();

//设置Zend Cache缓存时间、路径、是否自动更新。
$frontendOptions = array(
   'lifeTime' => 7200, // Cache缓存时间 2 hours 
   'automaticSerialization' => true
);
$backendOptions = array(
    'cacheDir' => 'views/cache/' // Directory where to put the cache files
);
// 取得一个Zend_Cache_Core 对象
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Zend_Registry::set('cache',$cache);


// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('./application/controllers');
$frontController->addModuleDirectory('./application/modules');
$frontController->setParam('noViewRenderer',true); 
$frontController->setBaseUrl($REL_ROOT_PATH);
// run!
$frontController->dispatch();